
********** This program generates the results in Table A7, Panel C, of the paper: robustness check controlling for network truncation *********

clear all
set more off, permanently
cd "$localdir\Data"
global output "$localdir\Output"


*** Construct datasets to control for network truncation
* Truncation controls: j higher education (as we only use most recent education network, and we already have education FE for i), j firm size >25 or j total workers >50, i firm size >25 or i total workers >50
* -> three dummy controls


* Workplace truncation info
forval i=2010/2013 {
use firmid_20082012.dta, clear
* Education links two years prior to the survey
g j=`i'-1
g k=`i'-2

keep if year>=k & year<=j

* Merge in the unique identifier (to replace pnr)
merge m:1 pnr using "Unique ID (pnr).dta"
drop if _merge==2
drop _merge 

g temp1=(workers>25 & workers!=.)
g temp2=(workers_total>=50)
bysort unique: egen temp1max=max(temp1)
bysort unique: egen temp2max=max(temp2)
egen workers_restriction=rowmax(temp1max temp2max)

keep unique workers_restriction
duplicates drop unique workers_restriction, force
g year=`i'

save workers_restriction_`i', replace
}

use workers_restriction_2010, clear
append using workers_restriction_2011 workers_restriction_2012 workers_restriction_2013
save workers_restriction, replace

* i-j-k dataset
use "i-j-k links for RF", clear

* Educ info for j
rename unique unique_i
rename unique_j unique
merge m:1 unique year using "Education codes.dta", keepusing(educ_code_1_digit)
replace educ_code_1_digit = 999 if _merge==1 
drop if _merge==2
drop _merge

rename unique unique_j
rename unique_i unique
rename educ_code_1_digit educ_code_1_digit_j

* Workers restriction info
rename unique unique_i
rename unique_j unique
merge m:1 unique year using workers_restriction
drop if _merge==2
drop _merge

rename unique unique_j
rename unique_i unique
rename workers_restriction workers_restriction_j

merge m:1 unique year using workers_restriction
drop if _merge==2
drop _merge

* Collapse to i-k level
g temp=(workers_restriction==1 & coworker==1)
bysort year unique unique_k: egen work_trunc_i=max(temp)
drop temp

g temp=(workers_restriction_j==1 & coworker_j==1)
bysort year unique unique_k: egen work_trunc_j=max(temp)
drop temp

g higher_educ_j=(educ_code_1_digit_j==60 | educ_code_1_digit_j==65)
g temp=(higher_educ_j==1 & educ_j==1)
bysort year unique unique_k: egen educ_trunc_j=max(temp)
drop temp

duplicates drop year unique unique_k, force
rename unique_k unique_network
keep year unique unique_network work_trunc_i work_trunc_j educ_trunc_j
save truncation, replace






***************************************************** ASSESSMENT OF NATIONAL UNEMPLOYMENT RATE ******************************************************

* Outcome only available in 2011 and 2012

use "National Unemployment RF for Analysis - Last Year.dta", clear

merge 1:1 year unique unique_network using truncation
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen work_trunc_i_share=mean(work_trunc_i)
bysort unique year: egen work_trunc_j_share=mean(work_trunc_j)
bysort unique year: egen educ_trunc_j_share=mean(educ_trunc_j)
drop *_network
duplicates drop unique year, force

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"

global controls = "work_trunc_i_share work_trunc_j_share educ_trunc_j_share"

replace unemp_rate_estimate=unemp_rate_estimate/100

* Results
display c(current_time)
reghdfe unemp_rate_estimate grossunemp_enter_network_share $controls, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum unemp_rate_estimate if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA7_PanelC.xls", replace nocons nor ctitle("Guess national unemployment rate") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock')

display c(current_time)









***************************************************** FORECAST OF NATIONAL UNEMPLOYMENT RATE ******************************************************

* Outcome only available in 2011

use "National Unemployment Forecast RF for Analysis - Last Year.dta", clear

merge 1:1 year unique unique_network using truncation
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen work_trunc_i_share=mean(work_trunc_i)
bysort unique year: egen work_trunc_j_share=mean(work_trunc_j)
bysort unique year: egen educ_trunc_j_share=mean(educ_trunc_j)
drop *_network
duplicates drop unique year, force

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"

global controls = "work_trunc_i_share work_trunc_j_share educ_trunc_j_share"

replace unemp_rate_estimate_next=unemp_rate_estimate_next/100

* Results
display c(current_time)
reghdfe unemp_rate_estimate_next grossunemp_enter_network_share $controls, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum unemp_rate_estimate_next if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA7_PanelC.xls", append nocons nor ctitle("National unemployment rate expectation") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock')

display c(current_time)







***************************************************** UNEMPLOYMENT OUTCOMES - PROBABILITY ******************************************************

use "Unemployment Outcomes RF for Analysis - Last Year.dta", clear

merge 1:1 year unique unique_network using truncation
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen work_trunc_i_share=mean(work_trunc_i)
bysort unique year: egen work_trunc_j_share=mean(work_trunc_j)
bysort unique year: egen educ_trunc_j_share=mean(educ_trunc_j)
drop *_network
duplicates drop unique year, force

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"

global controls = "work_trunc_i_share work_trunc_j_share educ_trunc_j_share"

replace prob_unemployed=prob_unemployed/100

* Results
display c(current_time)
reghdfe prob_unemployed grossunemp_enter_network_share $controls, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum prob_unemployed if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA7_PanelC.xls", append nocons nor ctitle("Own unemployment expectation") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock')

display c(current_time)












***************************************************** UNEMPLOYMENT OUTCOMES - UI POLICY ******************************************************

use "UI Outcomes RF for Analysis - Last Year.dta", clear

merge 1:1 year unique unique_network using truncation
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen work_trunc_i_share=mean(work_trunc_i)
bysort unique year: egen work_trunc_j_share=mean(work_trunc_j)
bysort unique year: egen educ_trunc_j_share=mean(educ_trunc_j)
drop *_network
duplicates drop unique year, force

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"

global controls = "work_trunc_i_share work_trunc_j_share educ_trunc_j_share"

* Results
display c(current_time)
reghdfe more_ui grossunemp_enter_network_share $controls, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum more_ui if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA7_PanelC.xls", append nocons nor ctitle("Want more unemployment insurance") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock')

display c(current_time)








***************************************************** IDEOLOGY OUTCOMES ******************************************************

use "Ideology RF for Analysis - Last Year.dta", clear

merge 1:1 year unique unique_network using truncation
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen work_trunc_i_share=mean(work_trunc_i)
bysort unique year: egen work_trunc_j_share=mean(work_trunc_j)
bysort unique year: egen educ_trunc_j_share=mean(educ_trunc_j)
drop *_network
duplicates drop unique year, force

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"

global controls = "work_trunc_i_share work_trunc_j_share educ_trunc_j_share"

* Results
display c(current_time)
reghdfe govt_more_help grossunemp_enter_network_share $controls, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum govt_more_help if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA7_PanelC.xls", append nocons nor ctitle("Government should support the poor") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock')

display c(current_time)











***************************************************** ECONOMIC POLICY ******************************************************

* These questions were not asked in 2012

use "Economic Policy Outcomes RF for Analysis - Last Year.dta", clear

merge 1:1 year unique unique_network using truncation
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen work_trunc_i_share=mean(work_trunc_i)
bysort unique year: egen work_trunc_j_share=mean(work_trunc_j)
bysort unique year: egen educ_trunc_j_share=mean(educ_trunc_j)
drop *_network
duplicates drop unique year, force

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"

global controls = "work_trunc_i_share work_trunc_j_share educ_trunc_j_share"

* Results
display c(current_time)
reghdfe gov_solution grossunemp_enter_network_share $controls, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum gov_solution if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA7_PanelC.xls", append nocons nor ctitle("Support non-market-based stimulus") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock')

display c(current_time)








***************************************************** VOTING LEFT (INTENTION) ******************************************************

use "Voting RF for Analysis - Last Year.dta", clear

merge 1:1 year unique unique_network using truncation
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen work_trunc_i_share=mean(work_trunc_i)
bysort unique year: egen work_trunc_j_share=mean(work_trunc_j)
bysort unique year: egen educ_trunc_j_share=mean(educ_trunc_j)
drop *_network
duplicates drop unique year, force

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"

global controls = "work_trunc_i_share work_trunc_j_share educ_trunc_j_share"

* Results
display c(current_time)
reghdfe vote_left grossunemp_enter_network_share $controls, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum vote_left if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA7_PanelC.xls", append nocons nor ctitle("Intend to vote for left party") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock')

display c(current_time)











***************************************************** VOTED LEFT ******************************************************

* These questions were only asked in 2011 - ie the year before which the shocks definitely occurred before the election

use "Voted RF for Analysis - Last Year.dta", clear

merge 1:1 year unique unique_network using truncation
keep if _merge==3
drop _merge

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen work_trunc_i_share=mean(work_trunc_i)
bysort unique year: egen work_trunc_j_share=mean(work_trunc_j)
bysort unique year: egen educ_trunc_j_share=mean(educ_trunc_j)
drop *_network
duplicates drop unique year, force

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"

global controls = "work_trunc_i_share work_trunc_j_share educ_trunc_j_share"

* Results
display c(current_time)
reghdfe voted_left_2011 grossunemp_enter_network_share $controls, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum voted_left_2011 if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
outreg2 using "$output\TableA7_PanelC.xls", append nocons nor ctitle("Voted for left party in 2001") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock')

display c(current_time)









































